package com.fas.system.controller;

import cn.hutool.core.lang.tree.Tree;
import com.fas.common.annotation.Log;
import com.fas.common.core.controller.BaseController;
import com.fas.common.core.domain.AjaxResult;
import com.fas.common.core.page.TableDataInfo;
import com.fas.common.enums.BusinessType;
import com.fas.system.domain.FasEquipmentManufacturer;
import com.fas.system.domain.SysArea;
import com.fas.system.service.IFasEquipmentManufacturerService;
import com.fas.system.service.ISysAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 设备属性 Controller
 *
 * @author lk
 * @date 2022-06-23
 */
@Api(tags = "设备基础属性")
@RestController
@RequestMapping("/system/equipment")
public class FasEquipmentAttributeController extends BaseController {


    @Resource
    private IFasEquipmentManufacturerService fasEquipmentManufacturerService;
    @Resource
    private ISysAreaService sysAreaService;

    /**
     * 添加设备厂商、类型、型号数据
     */
    @ApiOperation(value = "添加设备厂商、类型、型号数据")
//    @PreAuthorize("@ss.hasPermi('system:equipment:edit')")
    @Log(title = "厂商数据", businessType = BusinessType.INSERT)
    @PostMapping("/manufacturer")
    public AjaxResult insertManufacturer(@RequestBody FasEquipmentManufacturer fasEquipmentManufacturer)
    {
        return toAjax(fasEquipmentManufacturerService.insertManufacturer(fasEquipmentManufacturer));
    }

    /**
     * 查询设备厂商、类型、型号数据
     */
    @ApiOperation(value = "查询设备厂商、类型、型号数据")
//    @PreAuthorize("@ss.hasPermi('system:equipment:list')")
    @GetMapping("/manufacturer/list")
    public TableDataInfo findLikeEquipmentManufacturer(FasEquipmentManufacturer equipmentManufacturer) {

        List<Tree<String>> list = fasEquipmentManufacturerService.findLikeEquipmentManufacturer(equipmentManufacturer);
        return getDataTable(list);
    }

    /**
     * 查询所有省市区
     */
    @ApiOperation(value = "查询所有省市区")
//    @PreAuthorize("@ss.hasPermi('system:equipment:list')")
    @GetMapping("/area/list")
    public TableDataInfo findLikeEquipmentArea() {
        List<Tree<String>> list = sysAreaService.findLikeEquipmentArea();
        return getDataTable(list);
    }

    /**
     * 查询地区详细
     */
    @ApiOperation(value = "查询地区详细")
//    @PreAuthorize("@ss.hasPermi('system:equipment:list')")
    @GetMapping("/area/findNameByParentCode")
    public TableDataInfo findNameByParentCode(String parentCode) {
        List<SysArea> list = sysAreaService.findNameByParentCode(parentCode);
        return getDataTable(list);
    }

}
